package nowcoder;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

public class 四则运算 {

    /**
     * 3+2*{1+2*[-4/(8-6)+7]}
     *
     * 3-10+(0+(10+5+3)-10)
     *
     * @param args
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextLine()) {
            String line = scan.nextLine();
            if (line != null && line.length() > 0) {
                System.out.println(parse(line));
//                Tokenizer tokenizer = new Tokenizer(line);
//                while (tokenizer.hasNext()) {
//                    System.out.println(tokenizer.next());
//                }
            }
        }
    }

    public static int parse(String express) {
        LinkedList<Integer> numberStack = new LinkedList<>();
        LinkedList<Character> operatorStack = new LinkedList<>();

        Tokenizer tokenizer = new Tokenizer(express);
        while (tokenizer.hasNext()) {
            Object token = tokenizer.next();
            if (token instanceof Integer) {
                numberStack.addLast((Integer) token);
            } else {
                Character c = (Character) token;
                switch (c) {
                    case ')':
                    case ']':
                    case '}':
                        //括号结尾，必然可以计算，且计算到括号开始处
                        while (!Tokenizer.isPrefix(operatorStack.getLast())) {
                            computeOnce(numberStack, operatorStack);
                        }
                        operatorStack.pollLast();
                        continue;
                    case '(':
                    case '[':
                    case '{':
                        operatorStack.addLast(c);
                        continue;
                    case '-':
                    case '+':
                        //遇到加减法，如果前面的计算没算，则前面的计算可以触发了
                        Object next = tokenizer.next();
                        while (!operatorStack.isEmpty() && !Tokenizer.isPrefix(operatorStack.getLast())) {
                            computeOnce(numberStack, operatorStack);
                        }
                        if (next instanceof Integer) {
                            operatorStack.addLast(c);
                            numberStack.addLast((Integer) next);
                        } else {
                            operatorStack.addLast(c);
                            operatorStack.addLast((Character) next);
                        }
                        continue;
                    case '*':
                    case '/':
                        //遇到乘除法，除非后面是括号，否则可以优先计算
                        next = tokenizer.next();
                        if (next instanceof Integer) {
                            numberStack.addLast((Integer) next);
                            operatorStack.addLast(c);
                            computeOnce(numberStack, operatorStack);
                        } else {
                            operatorStack.addLast(c);
                            operatorStack.addLast((Character) next);
                        }
                        continue;
                }
            }
        }

        while (!operatorStack.isEmpty()) {
            computeOnce(numberStack, operatorStack);
        }
        return numberStack.poll();
    }

    public static void computeOnce(LinkedList<Integer> numberStack, LinkedList<Character> operatorStack) {
        int n2 = numberStack.pollLast();
        int n1 = numberStack.pollLast();
        char operator = operatorStack.pollLast();
        numberStack.addLast(doCompute(n1, n2, operator));
    }

    public static int doCompute(int n1, int n2, char operator) {
        if (operator == '+') {
            return n1 + n2;
        }
        if (operator == '-') {
            return n1 - n2;
        }
        if (operator == '*') {
            return n1 * n2;
        }
        return n1 / n2;
    }

}

class Tokenizer implements Iterator {

    /**
     * 解析的字符串
     */
    String str;

    /**
     * 解析位置
     */
    int index = 0;

    public Tokenizer(String str) {
        this.str = str.trim();
    }

    @Override
    public boolean hasNext() {
        return index < str.length();
    }

    /**
     * 返回Integer表示数字，返回Character表示计算符
     * @return
     */
    @Override
    public Object next() {
        int start = -1;
        while (index < str.length()) {
            char c = str.charAt(index);
            switch (c) {
                case ' ':
                    continue;
                case '-':
                    //负号
                    if (index < 1 || (!isNumber(str.charAt(index - 1)) && !isSuffix(str.charAt(index - 1)))) {
                        start = index++;
                        continue;
                    }
                case '{':
                case '}':
                case '(':
                case ')':
                case '[':
                case ']':
                case '*':
                case '/':
                case '+':
                    if (start < 0) {
                        index++;
                        return c;
                    } else {
                        String substring = str.substring(start, index);
                        return Integer.parseInt(substring);
                    }
                default:
                    if (start < 0) {
                        start = index;
                    }
                    index++;
                    if (index >= str.length()) {
                        String subString = str.substring(start);
                        return Integer.parseInt(subString);
                    }
            }
        }
        return null;
    }

    public static boolean isNumber(char c) {
        return c >= '0' && c <= '9';
    }

    public static boolean isPrefix(char c) {
        return c == '(' || c == '[' || c == '{';
    }

    public static boolean isSuffix(char c) {
        return c == ')' || c == ']' || c == '}';
    }
}
